package eight.test_8_11;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class TestMain2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = 0;
        int y = 0;
        int[] arr = new int[n];
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
            if(arr[i] == 0) {
                x++;
            } else {
                y++;
            }
        }
        for (int i = 0; i < n; i++) {
            int x1 = x;
            int y1 = y;
            for (int j = i; j < n; j++) {
                if(arr[j] == 0) {
                    x1--;
                    y1++;
                } else {
                    y1--;
                    x1++;
                }
                set.add(Math.abs(x1 - y1));
            }
        }
        System.out.println(set.size());
    }
}
